<?php
$countsearch    = array();
$countall       = 0;

function SearchProduct($url)
{
    global $dbsql,$language,$countsearch,$countall;
    TImport('product');
    
    $sql_where  = " from tblproduct where iStatus=1 and cLanguage='$language' ";
    $sql_where .= " and cUrlString like '%$url%'";
    
    $sql_select = "select count(iId) as count ".$sql_where;
    $result     = $dbsql->query_fetch($sql_select);
    list($lf,$la,$pages)= Split_Page($result['count'],'Ajax_product');
    
    $sql_select = "select iParentId,cUrlString,cName,cImage,cDescription ".$sql_where." order by iOrder limit $lf,$la";
    $rs         = $dbsql->query($sql_select);
    $rows       = $dbsql->num_rows($rs);
    if($rows==0)
    {
        return;
    }
    $countsearch[] = $rows;
    $countall     += $rows;
    $html_str   = '<div id="Ajax_product">';
    
    while($result  = $dbsql->fetch_array($rs))
    {
        $link      = GetLinkProduct($result['iParentId'],$result['cUrlString']);
        $imglink   = GetIntroImg($result['cImage'],true,false);
        $html_str .= '<div class="listsearch"><a href="'.echoLink($link,false).'">';              
        $html_str .= $result['cName'].'</a>';
        if($imglink)
        {
            $html_str .= '<span class="img"><img src="'.$imglink.'" border=0/></span>';
        }  
        $html_str .= strSplitSub($result['cDescription'],50).'</div><div class="clear"></div>';
    }
    $html_str     .= $pages;
    $html_str     .= '</div>';
    
    return $html_str;
}

function SearchCategory($url)
{
    global $dbsql,$language,$countsearch,$countall;
    
    $sql_where  = " from tblcategory where iStatus=1 and cLanguage='$language' ";
    $sql_where .= " and cUrlString like '%$url%'";
    
    $sql_select = "select count(iId) as count ".$sql_where;
    $result     = $dbsql->query_fetch($sql_select);
    list($lf,$la)= Split_Page($result['count'],'Ajax_Cats');
    
    $sql_select = "select * ".$sql_where." order by iOrder limit $lf,$la";
    $rs         = $dbsql->query($sql_select);
    $rows       = $dbsql->num_rows($rs);
    if($rows==0)
    {
        return;
    }
    $countsearch[] = $rows;
    $countall     += $rows;
    $html_str   = '<div id="Ajax_Cats">';
    
    while($result  = $dbsql->fetch_array($rs))
    {
        $link      = getLinkParentCat($result['iParentId']).'/'.$result['cUrlString'];
        $imglink   = GetIntroImg($result['cImage'],true,false);
        $html_str .= '<div class="listsearch"><a href="'.echoLink($link,false).'">';
               
        $html_str .= $result['cName'].'</a>';
        if($imglink)
        {
            $html_str .= '<span class="img"><img src="'.$imglink.'" border=0></span>';
        } 
        $html_str .= strSplitSub($result['cDescription'].$result['cIntro'],50).'</div><div class="clear"></div>';
    }
    $html_str     .= $pages;
    $html_str     .= '</div>';
    //echo $html_str;exit;
    return $html_str;
}

function SearchContent($url)
{
    global $dbsql,$language,$countsearch,$countall;
    
    $sql_where  = " from tblcontent where iStatus=1 and cLanguage='$language' ";
    $sql_where .= " and cUrlString like '%$url%'";
    
    $sql_select = "select count(iId) as count ".$sql_where;
    $result     = $dbsql->query_fetch($sql_select);
    list($lf,$la)= Split_Page($result['count'],'Ajax_Contents');
    
    $sql_select = "select * ".$sql_where." order by iOrder limit $lf,$la";
    $rs         = $dbsql->query($sql_select);
    $rows       = $dbsql->num_rows($rs);
    if($rows==0)
    {
        return;
    }
    $countsearch[] = $rows;
    $countall     += $rows;
    $html_str   = '<div id="Ajax_Contents">';
    
    while($result  = $dbsql->fetch_array($rs))
    {
        $link      = getLinkParentCat($result['iParentId']).'/'.$result['cUrlString'].'.htm';
        $imglink   = GetIntroImg($result['cImage'],true,false);
        $html_str .= '<div class="listsearch"><a href="'.echoLink($link,false).'">';
               
        $html_str .= $result['cName'].'</a>';
        if($imglink)
        {
            $html_str .= '<span class="img"><img src="'.$imglink.'" border=0></span>';
        } 
        $html_str .= strSplitSub($result['cDescription'].$result['cIntro'],50).'</div><div class="clear"></div>';
    }
    $html_str     .= $pages;
    $html_str     .= '</div>';
    //echo $html_str;exit;
    return $html_str;
}

function SearchNews($url)
{
    global $dbsql,$language,$countsearch,$countall;
    
    $sql_where  = " from tblnews_content where iStatus=1 and cLanguage='$language' ";
    $sql_where .= " and cUrlString like '%$url%'";
    
    $sql_select = "select count(iId) as count ".$sql_where;
    $result     = $dbsql->query_fetch($sql_select);
    list($lf,$la)= Split_Page($result['count']);
    
    $sql_select = "select * ".$sql_where." order by iOrder limit $lf,$la";
    $rs         = $dbsql->query($sql_select);
    $rows       = $dbsql->num_rows($rs);
    if($rows==0)
    {
        return;
    }
    $countsearch[] = $rows;
    $countall     += $rows;
    $html_str   = '<div id="Ajax_Contents">';
    
    while($result  = $dbsql->fetch_array($rs))
    {
        $link      = getLinkParentCat($result['iParentId']).'/'.$result['cUrlString'].'.htm';
        $imglink   = GetIntroImg($result['cImage'],true,false);
        $html_str .= '<div class="listsearch"><a href="'.echoLink($link,false).'">';
               
        $html_str .= $result['cName'].'</a>';
        if($imglink)
        {
            $html_str .= '<span class="img"><img src="'.$imglink.'" border=0></span>';
        } 
        $html_str .= strSplitSub($result['cDescription'],50).'</div><div class="clear"></div>';
    }
    $html_str     .= $pages;
    $html_str     .= '</div>';
    //echo $html_str;exit;
    return $html_str;
}